package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GxzyfYpzd;
import com.ruoyi.system.service.IGxzyfYpzdService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药房字典注册Controller
 * 
 * @author GXzyf
 * @date 2022-09-13
 */
@Controller
@RequestMapping("/system/ypzd")
public class GxzyfYpzdController extends BaseController
{
    private String prefix = "system/ypzd";

    @Autowired
    private IGxzyfYpzdService gxzyfYpzdService;

    @RequiresPermissions("system:ypzd:view")
    @GetMapping()
    public String ypzd()
    {
        return prefix + "/ypzd";
    }

    /**
     * 查询药房字典注册列表
     */
    @RequiresPermissions("system:ypzd:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GxzyfYpzd gxzyfYpzd)
    {
        startPage();
        List<GxzyfYpzd> list = gxzyfYpzdService.selectGxzyfYpzdList(gxzyfYpzd);
        return getDataTable(list);
    }

    /**
     * 导出药房字典注册列表
     */
    @RequiresPermissions("system:ypzd:export")
    @Log(title = "药房字典注册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GxzyfYpzd gxzyfYpzd)
    {
        List<GxzyfYpzd> list = gxzyfYpzdService.selectGxzyfYpzdList(gxzyfYpzd);
        ExcelUtil<GxzyfYpzd> util = new ExcelUtil<GxzyfYpzd>(GxzyfYpzd.class);
        return util.exportExcel(list, "药房字典注册数据");
    }

    /**
     * 新增药房字典注册
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存药房字典注册
     */
    @RequiresPermissions("system:ypzd:add")
    @Log(title = "药房字典注册", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GxzyfYpzd gxzyfYpzd)
    {
        return toAjax(gxzyfYpzdService.insertGxzyfYpzd(gxzyfYpzd));
    }

    /**
     * 修改药房字典注册
     */
    @RequiresPermissions("system:ypzd:edit")
    @GetMapping("/edit/{药品ID}")
    public String edit(@PathVariable("药品ID") String 药品ID, ModelMap mmap)
    {
        GxzyfYpzd gxzyfYpzd = gxzyfYpzdService.selectGxzyfYpzdBy药品ID(药品ID);
        mmap.put("gxzyfYpzd", gxzyfYpzd);
        return prefix + "/edit";
    }

    /**
     * 修改保存药房字典注册
     */
    @RequiresPermissions("system:ypzd:edit")
    @Log(title = "药房字典注册", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GxzyfYpzd gxzyfYpzd)
    {
        return toAjax(gxzyfYpzdService.updateGxzyfYpzd(gxzyfYpzd));
    }

    /**
     * 删除药房字典注册
     */
    @RequiresPermissions("system:ypzd:remove")
    @Log(title = "药房字典注册", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gxzyfYpzdService.deleteGxzyfYpzdBy药品IDs(ids));
    }
}
